package 设计模式;

/**
 * @Author: 李浩然
 * @Date: 2021/1/10 3:24 下午
 */
public class 多线程单例模式 {
}

class Single {
    private static volatile Single s = null;

    private Single() {
    }

    private static Single getInstance() {
        if (s == null) {
            synchronized (Single.class) {
                if (s == null) {
                    s = new Single();
                }
            }
        }
        return s;
    }
}

class Single1_1 {
    private static class InstanceHolder {
        public static Single1_1 instance = new Single1_1();
    }

    public static Single1_1 getInstance() {
        return InstanceHolder.instance;
    }
}
